// pages/history/history.js
const config = require('../../config.js')
const http = require('../../http.js')
var page = 1
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isRefresh:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    page = 1
    this.getConferences(page)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  toRanking:function(e){
    wx.navigateTo({
      url: '../ranking/ranking?id='+e.currentTarget.dataset.id,
    })
  },
  
  bindscrolltolower:function(){
    console.log("bindscrolltolower")
    page++
    this.getConferences(page)
  },

  bindrefresherrefresh:function(){
    console.log("bindrefresherrefresh")
    this.setData({
      isRefresh:true
    })
    page = 1
    this.getConferences(page)
  },
  getConferences:function(p){
    var that = this
    http.request(
      config.conferences,
      'GET', {
        page:p,
        pageSize:10,
        type:1
      },
      function (res) {
        if (res.data != null) {
          if(p == 1){
            that.setData({
              historyData:res.data
            })
          }else{
            that.setData({
              historyData:that.data.historyData.concat(res.data)
            })
          }
        }
        if(that.data.isRefresh){
          that.setData({
            isRefresh:false
          })
        }
      },
      function (err) {
        wx.showToast({
          title: err,
          icon: 'none',
        })
      }
    )
  },
})